package cn.com.surker.base.system.service.impl;

import cn.com.surker.base.pump.dao.PumpNormDao;
import cn.com.surker.base.pump.entity.PumpNorm;
import cn.com.surker.base.pump.service.PumpNormService;
import cn.com.surker.base.system.dao.SysLineDao;
import cn.com.surker.base.system.entity.SysLine;
import cn.com.surker.base.system.service.SysLineService;
import cn.com.surker.enums.StateEnum;
import cn.com.surker.enums.system.DataBaseEnum;
import cn.com.surker.system.dao.DataSourceInfoDao;
import cn.com.surker.system.entity.DataSourceInfo;
import cn.com.surker.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 泵送规格 基础实现
 * </p>
 *
 * @author admin
 * @since 2024-07-09
 */
public abstract class SysLineBaseImpl extends ServiceImpl<SysLineDao, SysLine> implements SysLineService {

	@Resource
	protected SysLineDao sysLineDao;
	@Resource
	protected DataSourceInfoDao dsDao;

	@Override
	public List<SysLine> findList(String name) {
		QueryWrapper<SysLine> qw = new QueryWrapper<>();
		qw.eq("status", StateEnum.ENABLED.getCode());
		if (StringUtils.isNotBlank(name)) {
			qw.like("name", name);
		}
		qw.orderByAsc("name");
		List<SysLine> lines = sysLineDao.selectList(qw);
		return lines;
	}

	/**
	 * 查询生产线
	 * @param orgId
	 * @param name
	 * @return
	 */
	public List<SysLine> findByOrg(Long orgId, String name) {
		if (StringUtils.isNull(orgId))
			return null;
		DataSourceInfo ds = dsDao.queryDSByOriginIdV1(orgId, DataBaseEnum.MYSQL.getCode());
		if (ds == null || ds.getType() != 0)
			return null;
		if (StringUtils.isNull(name))
			name = null;
		List<SysLine> lines = sysLineDao.findByDbCode(ds.getCode(), name);
		return lines;
	}
}